const path = require('path');
// 动态改变url的hash值
const HtmlWebpackPlugin = require('html-webpack-plugin');

const MiniCssExtractPlugin = require("mini-css-extract-plugin");

module.exports = {
  entry: './main.js',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: '[name].js',
  },
  mode: 'development',
  module: {
    rules: [{
      test: /\.css$/,
      use: [MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader'], // MiniCssExtractPlugin.loader和style.loader不能共同使用
    }]
  },
  plugins: [
    new HtmlWebpackPlugin({
      minify: {
        collapseWhitespace:true, // 折叠空白区域 也就是压缩代码
        removeAttributeQuotes:true // 移除双引号，更多配置可以查看插件官网
      },
      template: 'index.html' // 生成dist文件的html，但是要安好足啊去过webpack和webpack-cli
    }),
    new MiniCssExtractPlugin({
      filename: "[name].css",
      chunkFilename: "[id].css"
    }),
  ]
};